package org.budo.support.spring.http.converter.json;

import java.io.IOException;
import java.lang.reflect.Type;

import org.budo.support.lang.util.IoUtil;
import org.budo.support.lang.util.StringUtil;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

/**
 * @author lmw
 */
public class BudoMappingJacksonHttpMessageConverter extends MappingJackson2HttpMessageConverter {
    @Override
    protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
        if (null != object && object instanceof String && StringUtil.startsWith((String) object, "{") && StringUtil.endsWith((String) object, "}")) {
            IoUtil.write((String) object, outputMessage.getBody());
            return;
        }

        super.writeInternal(object, type, outputMessage);
    }
}